package main

import "fmt"

func romanToInt(s string) int {
	//Number := [5]int{1, 5, 10, 50, 100, 500, 1000}
	//type Number struct {
	//	I int
	//	V int
	//	X int
	//	L int
	//	C int
	//	D int
	//	M int
	//}
	//n := Number{I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000}
	var sum = 0
	for a, b := range s {
		switch string(b) {
		case "I":
			{
				if a+1 < len(s) {
					char := s[a+1]
					if string(char) == "V" || string(char) == "X" {
						sum = sum - 1
					} else {
						sum = sum + 1
					}
				} else {
					sum = sum + 1
				}

			}
		case "V":
			sum = sum + 5
		case "X":
			{
				if a+1 < len(s) {
					char := s[a+1]
					if string(char) == "L" || string(char) == "C" {
						sum = sum - 10
					} else {
						sum = sum + 10

					}
				} else {
					sum = sum + 10

				}
			}
		case "L":
			sum = sum + 50
		case "C":
			{
				if a+1 < len(s) {
					char := s[a+1]
					if string(char) == "D" || string(char) == "M" {
						sum = sum - 100
					} else {
						sum = sum + 100
					}
				} else {
					sum = sum + 100
				}
			}
		case "D":
			sum = sum + 500
		case "M":
			sum = sum + 1000
		}
		//fmt.Printf("char: %d, type: %T\n", a, a)
		//fmt.Printf("char: %c, type: %T\n", b, b)
	}
	return sum
}

//func romanToInt(s string) int {
//
//}

func main() {
	a := "III"
	fmt.Println("a的值为：", romanToInt(a))
	//fmt.Println("3的值为：", romanToInt("III"))
	//fmt.Println("58的值为：", romanToInt("LVIII"))
	//fmt.Println("9的值为：", romanToInt("IX"))
}
